package cn.calm.dialog;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import cn.calm.commons.dao.IBaseDao;
import cn.calm.dialog.service.IDialogService;
import cn.calm.dialog.service.impl.DialogServiceImpl;
import cn.calm.entity.Dialog;

public class Activator implements BundleActivator {
	public BundleContext context;

	@Override
	public void start(BundleContext context) throws Exception {
		this.context=context;
		ServiceReference<IBaseDao> serviceRef=context.getServiceReference(IBaseDao.class);
		IBaseDao dao=context.getService(serviceRef);
		IDialogService<Dialog> dialogService=new DialogServiceImpl<Dialog>();
		EntityManager em=Persistence.createEntityManagerFactory("entity").createEntityManager();
		dao.setSession(em);
		dialogService.setBaseDao(dao);
		context.registerService(IDialogService.class, dialogService, null);
	}

	@Override
	public void stop(BundleContext arg0) throws Exception {

	}

}
